package com.pattern.factory.abst;

/**
 * 抽象工厂模式 ： 围绕一个超级工厂创建其他工厂。该超级工厂又称为其他工厂的工厂
 * @author LYao15
 */

/**
 * 1、定义抽象产品 抽象类或接口
 */
abstract class KeyBo{
    public abstract void start();
}
abstract class Mouse{
    public abstract void start();
}
/**
 * 2、具体产品实现
 */
class HpKeyBo extends KeyBo{

    @Override
    public void start() {
        System.out.println("惠普键盘");
    }
}
class DellKeyBo extends KeyBo{

    @Override
    public void start() {
        System.out.println("戴尔键盘");
    }
}
class HpMouse extends Mouse{

    @Override
    public void start() {
        System.out.println("惠普鼠标");
    }
}
class DellMouse extends Mouse{

    @Override
    public void start() {
        System.out.println("戴尔鼠标");
    }
}

/**
 * 3、抽象超级工厂
 *    生产不同种类的产品，子工厂
 */
abstract class DeviceFactory{
    //生产鼠标
    public abstract Mouse createMouse();
    //生产键盘
    public abstract KeyBo createKeyBo();
}

/**
 * 4、具体工厂
 */
//戴尔工厂
class DellDeviceFactory extends DeviceFactory{

    @Override
    public Mouse createMouse() {
        return new DellMouse();
    }

    @Override
    public KeyBo createKeyBo() {
        return new DellKeyBo();
    }
}
//惠普工厂
class HpDeviceFactory extends DeviceFactory{

    @Override
    public Mouse createMouse() {
        return new HpMouse();
    }

    @Override
    public KeyBo createKeyBo() {
        return new HpKeyBo();
    }
}

/**
 * @author LYao15
 */
public class AbstractFactoryTest {
    public static void main(String[] args) {

        //制造惠普鼠标 键盘
        DeviceFactory factory = new HpDeviceFactory();

        KeyBo keyBo = factory.createKeyBo();
        Mouse mouse = factory.createMouse();
        keyBo.start();
        mouse.start();
    }
}
